Back to Main Menu

Create Work Request (Assetic Python SDK)

Introduction

The Assetic Python SDK may be used to simplify creation of a Work Request.

Review the integration article Create Work Request to understand the purpose of each field, typical default values, and typical integration payloads.

Code Sample

The following example creates a new request using the Assetic Python SDK.

  1. """
  2. Example script to create a request (Assetic.WorkRequestCreate.py)
  3. Creates a customer request in Assetic
  4. """
  5. import assetic
  6. ##Assetic SDK instance.
  7. asseticsdk = assetic.AsseticSDK("c:/users/kwilton/assetic.ini",None,"Info")
  8. ##work request API
  9. wrapi = assetic.WorkRequestApi()
  10. #create object for work request
  11. wr = assetic.Assetic3IntegrationRepresentationsWorkRequest()
  12. wr.external_identifier = "12345"
  13. wr.work_request_source_id = 3 #3="External CRM"
  14. wr.work_request_priority_id = 1
  15. wr.location = "Outside 7-Eleven Store"
  16. wr.feedback_method_id = 1
  17. wr.feedback_required = 0
  18. wr.description = "Sample API request generation - please fix pothole"
  19. ##Assign asset to work request using asset ID
  20. wr.asset_id = "AP01"
  21. ##create address object and fill in address detail
  22. wraddr = assetic.Assetic3IntegrationRepresentationsCustomAddress()
  23. wraddr.street_number = "257"
  24. wraddr.street_address = "Collins Street"
  25. wraddr.city_suburb = "Melbourne"
  26. wraddr.state = "Victoria"
  27. wraddr.zip_postcode = "3000"
  28. wraddr.country = "Australia"
  29. ##create object for location which holds address and assign to work request
  30. wrfl = assetic.Assetic3IntegrationRepresentationsWorkRequestPhysicalLocation()
  31. wrfl.address = wraddr
  32. wr.work_request_physical_location = wrfl
  33. ##create object for spatial location and assign to work request object
  34. wrsl = assetic.Assetic3IntegrationRepresentationsWorkRequestSpatialLocation()
  35. wrsl.point_string = "POINT (145.247206 -37.857442)"
  36. wr.work_request_spatial_location = wrsl
  37. #create object for person that lodged the request. Set first & family name
  38. wrreq = assetic.Assetic3IntegrationRepresentationsRequestorRepresentation()
  39. wrreq.first_name = "Miles"
  40. wrreq.surname = "Moncrief"
  41. ##assign requestor to work request
  42. wr.requestor = wrreq
  43. ##Now create the work request
  44. try:
  45. wrguid = wrapi.work_request_post(wr) #returns guid of work request
  46. except assetic.rest.ApiException as e:
  47. asseticsdk.logger.error("Status {0}, Reason: {1}".format(e.status,e.reason))
  48. exit()
  49. if wrguid == None:
  50. asseticsdk.logger.warning("No work request GUID returned")
  51. exit()
  52. ##now get request back so we can see the generated user friendly Request ID
  53. try:
  54. wrget = wrapi.work_request_get(wrguid)
  55. except assetic.rest.ApiException as e:
  56. asseticsdk.logger.error("Status {0}, Reason: {1}".format(e.status,e.reason))
  57. exit()
  58. asseticsdk.logger.info("Work Request GUID: {0}, Friendly ID {1}".format(
  59. wrguid,wrget.get("FriendlyIdStr")))